//
//  LOLMvPlayerViewController.m
//  LOLXXbox
//
//  Created by mac on 16/3/1.
//  Copyright © 2016年 Grasstrio. All rights reserved.
//

#import "LOLMvPlayerViewController.h"
#import "CYVideoPlayerView.h"
#import <AVFoundation/AVFoundation.h>
#import "CYFullViewController.h"
#import "PrefixHeader.pch"
#import "LOLHeroViewController.h"
#import "ViewController.h"
@interface LOLMvPlayerViewController ()<CYVideoPlayerDelegate>
@property (nonatomic,strong) CYVideoPlayerView *playerView;

@property (nonatomic,strong) CYFullViewController *fullViewController;
@end

@implementation LOLMvPlayerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.playerView = [[CYVideoPlayerView alloc] init];
    self.playerView.delegate = self;
    [self.view addSubview:self.playerView];
    self.playerView.frame = CGRectMake(0, self.view.bounds.size.width / 2, self.view.frame.size.width, self.view.bounds.size.width * 9 / 16);
    self.navigationController.navigationBarHidden = YES;
    // 传一个 AVPlayerItem 如果能够播放视频就会调用play方法
    [self.playerView replaceAVPlayerItem:[[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:self.play_url]]];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 50, 50);
    [button setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonDidPress:) forControlEvents: UIControlEventTouchUpInside];
    [self.playerView addSubview:button];
    
    

}
- (void)buttonDidPress:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}



#pragma mark - CYVideoPlayerDelegate
/** <是否全屏播放视频> */
- (void)cyVideoToolBarView:(CYVideoToolBar *)cyVideoToolBar shouldFullScreen:(BOOL)isFull
{
    if (isFull) {
        self.fullViewController = [[CYFullViewController alloc] init];
        [self.fullViewController.view addSubview:self.playerView];
        [self.playerView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.removeExisting = YES;
        }];
        [self.playerView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.fullViewController.view);
        }];
        [self presentViewController:self.fullViewController animated:NO completion:nil];
    }else
    {
        [self.fullViewController dismissViewControllerAnimated:NO completion:^{
            [self.view addSubview:self.playerView];
            self.fullViewController = nil;
           self.playerView.frame = CGRectMake(0, self.view.bounds.size.width / 2, self.view.frame.size.width, self.view.bounds.size.width * 9 / 16);
        }];
    }
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
